package nccloud.mob.riart.message.actions;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;

import nc.vo.ml.NCLangRes4VoTransl;
import nccloud.framework.core.json.IJson;
import nccloud.framework.mob.action.itf.IMobileAction;
import nccloud.framework.mob.container.IMobRequest;
import nccloud.framework.web.json.JsonFactory;
import nccloud.pubitf.platform.attachment.WebFileParaVO;
import nccloud.mob.util.erm.webpub.AttchmentQueryUtil;

public class AttachmentQueryAction implements IMobileAction {
	public Object doAction(IMobRequest request) {
		String str = request.read();
		IJson json = JsonFactory.create();
		WebFileParaVO para = (WebFileParaVO) json.fromJson(str, WebFileParaVO.class);
		WebFileParaVO[] returnvo = null;
		String fullPath = para.getFullPath();
		String folderName = NCLangRes4VoTransl.getNCLangRes().getStrByID("2011nccloud", "02011001-0041");
		List webFileParaVOs;
		if (fullPath.contains("/")) {
			if (fullPath.contains("/" + folderName)) {
				webFileParaVOs = AttchmentQueryUtil.getYhhdByBillid(para.getBillId());
				if (CollectionUtils.isNotEmpty(webFileParaVOs)) {
					returnvo = (WebFileParaVO[]) webFileParaVOs.toArray(new WebFileParaVO[0]);
				} else {
					returnvo = (WebFileParaVO[]) (new ArrayList()).toArray(new WebFileParaVO[0]);
				}
			} else {
				returnvo = AttchmentQueryUtil.billEnclosureQuery(fullPath, para.getBillId());
			}
		} else {
			webFileParaVOs = AttchmentQueryUtil.getYhhdByBillid(para.getBillId());
			WebFileParaVO[] webFileParaVO = AttchmentQueryUtil.billEnclosureQuery(fullPath, para.getBillId());
			WebFileParaVO[] webFileParaVO2 = null;
			if (CollectionUtils.isNotEmpty(webFileParaVOs)) {
				webFileParaVO2 = (WebFileParaVO[]) webFileParaVOs.toArray(new WebFileParaVO[0]);
			} else {
				webFileParaVO2 = (WebFileParaVO[]) (new ArrayList()).toArray(new WebFileParaVO[0]);
			}

			returnvo = (WebFileParaVO[]) ((WebFileParaVO[]) ArrayUtils.addAll(webFileParaVO, webFileParaVO2));
		}

		return returnvo;
	}


}